import { put, delay, fork, take, race, call } from 'redux-saga/effects'
import { actionTypes, increase } from '../action/counter'

// 自动增加和停止的流程控制
function* autoFork() {
    while (true) {
        yield take(actionTypes.autoIncrease);
        yield race({
            auto: call(function* () {
                while (true) {
                    yield delay(2000)
                    yield put(increase())
                }
            }),
            stop: take(actionTypes.stopAutoIncrease)
        })
    }
}
export default function* () {
    yield fork(autoFork)
}